<template>
	<view class="container">
		<view class="ListBox">
			<view class="ListItem" v-for="item in list" v-if="list.length>0">
				<view class="list">
					<text class="name">{{app.language.hjzm}}</text>
					<text class="jg" v-if="item.examineStatus=='1'">{{app.language.shtg}}</text>
					<text class="jgNo" v-if="item.examineStatus=='0'">{{app.language.shbtg}}</text>
					<text class="jgD" v-if="item.examineStatus==null">{{app.language.dsp}}</text>
				</view>
				<view class="sqTime">{{app.language.sqTime}}：{{item.createTime}}</view>
				<view class="sqTime" v-if="item.examineStatus=='0'">{{app.language.btgyy}}：{{item.examineOpinion}}
				</view>
				<view class="cb" v-if="item.examineStatus==null">
					{{app.language.cbPhone}}：{{item.cbphone}}
				</view>
				<view v-if="item.satisfaction&&item.examineStatus=='1'||item.examineStatus=='0'">
					{{app.language.pjBtn}}：{{item.satisfaction}}
				</view>
				<!-- 图片下载 -->
				<view v-if="item.examineStatus=='1'">
					<button class="pjBnT" @click="pjbtnxz(item)">下载打印</button>
				</view>
				<!-- 评价按钮 -->
				<view v-if="!item.satisfaction&&item.examineStatus=='1'||item.examineStatus=='0'">
					<button class="pjBnT" @click="pjBnT(item)">{{app.language.pjBtn}}</button>
				</view>
			</view>
			<view class="list" v-if="list.length==0">
				<nullVue></nullVue>
			</view>
			<!-- 弹窗 -->
			<uni-popup ref="popup" type="bottom" border-radius="10px 10px 0 0" class="popup">
				<view class="mysBox">
					<view class="fk">{{app.language.fkjg}}</view>
					<view class="pingj">
						<l-starRate v-model="pjval" @input="getvalue" :disabled="false"></l-starRate>
					</view>
					<view class="pjtext">{{pjtext}}</view>
					<button class="pjBtn" @click="pjBtn">{{app.language.tijiaopj}}</button>
				</view>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import {
		getIssueCertificateList,
		getupdateIssueCertificate
	} from '@/api/domicile.js'
	import nullVue from '@/components/null';
	import {
		getAppointmentReviewList
	} from '@/api/domicile.js'
	const global = getApp().globalData;
	export default {
		components: {
			nullVue
		},
		data() {
			return {
				app: {
					global: global,
					name: global.appName,
					language: global.language
				},
				token: "",
				userInfo: {},
				list: [],
				pjval: "",
				pjtext: "",
				info: {},
			}
		},

		onLoad() {
			this.getToken()
			setTimeout(() => {
				this.getList()
			}, 1000);

		},
		methods: {
			getToken() {
				let that = this
				uni.getStorage({
					key: 'loginData',
					success: function(res) {
						that.token = res.data.userInfo.appToken
						that.userInfo = res.data.userInfo
					}
				});
			},
			pjBnT(item) {
				console.log('item', item)
				this.info = item
				this.$refs.popup.open('center')
			},

			// 评价
			getvalue(val) {
				this.pjval = val
				console.log('this.pjval', this.pjval)
				if (this.pjval == 1) {
					this.pjtext = this.app.language.fcbmy
				} else if (this.pjval == 2) {
					this.pjtext = this.app.language.bmy
				} else if (this.pjval == 3) {
					this.pjtext = this.app.language.yb
				} else if (this.pjval == 4) {
					this.pjtext = this.app.language.my
				} else if (this.pjval == 5) {
					this.pjtext = this.app.language.fcmy
				}
			},

			// 提交反馈
			pjBtn() {
				if (!this.pjtext) {
					uni.showToast({
						title: this.app.language.qxfk,
						icon: 'none',
					});
					return
				}
				uni.showLoading({
					title: this.app.language.jzz,
				});
				let data = {
					appToken: this.token,
					uuid: this.info.uuid,
					satisfaction: this.pjtext
				}

				getupdateIssueCertificate(data).then((res) => {
					if (res.code == 200) {
						uni.hideLoading();
						uni.showToast({
							title: this.app.language.success,
							icon: 'success',
						});
						setTimeout(() => {
							console.log('跳转首页')
							uni.reLaunch({
								url: '/pages/related/index'
							});
						}, 1000);
					}

				})
			},

			// 查列表数据
			getList() {
				uni.showLoading({
					title: this.app.language.jzz,
				});
				let data = {
					appToken: this.token,
					// uuid: this.userInfo.uuid
				}
				getIssueCertificateList(data).then((res) => {
					if (res.code == 200) {
						uni.hideLoading();
						for (let i = 0; i < res.data.length; i++) {
							if(res.data[i].satisfaction==null){
								res.data[i].satisfaction = this.app.language.wu
							}
						}

						if (res.data.length > 0) {
							this.list = res.data
							const date = new Date();
							for (let i = 0; i < this.list.length; i++) {
								const y = new Date(this.list[i].createTime).getFullYear();
								const m = new Date(this.list[i].createTime).getMonth() + 1; // 月份是从0开始的
								const d = new Date(this.list[i].createTime).getDate();
								this.list[i].createTime =
									`${y}-${m.toString().padStart(2, '0')}-${d.toString().padStart(2, '0')}`;
							}
							console.log('this.list', this.list)
						}
					}

				})
			},
			pjbtnxz(item){
				console.log('下载',item)
			}

		},
	}
</script>

<style>
	.container {
		padding: 20rpx;
	}

	.ListItem {
		background-color: #fff;
		box-shadow: 2rpx 2rpx 10rpx #ddd;
		border-radius: 5rpx;
		margin-bottom: 20rpx;
		padding: 15rpx;
		position: relative;
	}

	.list {
		display: flex;
		border-bottom: 1px solid #ebebeb;
		padding: 10rpx 0;
	}

	.name {
		font-weight: bold;
		margin-bottom: 10rpx;
		font-size: 26rpx;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
		overflow: hidden;
		text-overflow: ellipsis;
		width: 66%;
	}

	.jg {
		margin-left: auto;
		font-size: 24rpx;
		border: 1px solid #59bea0;
		padding: 5rpx 10rpx;
		border-radius: 5rpx;
		color: #59bea0;
		width: 123rpx;
		text-align: center;
	}

	.sqTime {
		margin: 25rpx 0;
		font-size: 26rpx;
	}

	.cb {
		font-size: 26rpx;
	}

	.jgNo {
		margin-left: auto;
		font-size: 24rpx;
		border: 1px solid #d6605c;
		padding: 5rpx 10rpx;
		border-radius: 5rpx;
		color: #d6605c;
		width: 123rpx;
		text-align: center;
	}

	.jgD {
		margin-left: auto;
		font-size: 24rpx;
		border: 1px solid #909399;
		padding: 5rpx 10rpx;
		border-radius: 5rpx;
		color: #909399;
		width: 123rpx;
		text-align: center;
	}

	.pjBnT {
		background-color: #2f8ef9;
		font-size: 25rpx;
		color: #fff;
		width: 121rpx;
		height: 53rpx;
		line-height: 53rpx;
		position: absolute;
		right: 10rpx;
		bottom: 22rpx;

	}


	.popup {
		background: #fff;
		padding: 10rpx;
	}

	.mysBox {
		background: #fff;
		width: 700rpx;
		padding: 86rpx 0px 46rpx;
		border-radius: 5rpx;
	}

	.pjBtn {
		background: #2f8ef9;
		color: #fff;
		font-size: 26rpx;
		width: 80%;
		margin-top: 46rpx;
		color: #fff;
	}

	.pingj {
		width: 254rpx;
		margin: 0 auto;
	}

	.pjtext {
		text-align: center;
		font-size: 24rpx;
		margin-top: 15rpx;
	}

	.fk {
		text-align: center;
		font-size: 28rpx;
		margin-bottom: 20rpx;
	}
</style>